package com.banciyuan.bcywebview.base.fragment;

import android.os.Bundle;

//为了实现selfUpdateData的公共方法，不过也可以用接口实现。。。应该说最好用接口实现，继承不是用来干这个的，但我没时间了，请修改
public class BaseLazyContainerFragment extends BaseContainerFragment {

    protected boolean isViewInitiated;
    protected boolean isVisibleToUser;
    protected boolean isDataInitiated;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        isViewInitiated = true;
        prepareFetchData();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        this.isVisibleToUser = isVisibleToUser;
        prepareFetchData();
    }


    public void fetchData() {
    }

    public boolean prepareFetchData() {
        return prepareFetchData(false);
    }


    public boolean prepareFetchData(boolean forceUpdate) {
        if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) {
            fetchData();
            isDataInitiated = true;
            return true;
        }
        return false;
    }

    public boolean isVisibleToUser() {
        return isVisibleToUser;
    }

    public void setDataInitiated(boolean dataInitiated) {
        isDataInitiated = dataInitiated;
    }

    public void selfUpdateData() {
    }


}